package com.aerotechnic.service.implementation;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.StringTokenizer;

import org.springframework.transaction.annotation.Transactional;

import com.aerotechnic.dao.implementation.BaseDao;
import com.aerotechnic.entities.BaseEntity;

@Transactional
public abstract class BaseBo<E extends BaseEntity> extends BaseDao<E> implements BOLayer<E> {
	private Class<E> type;
	private String currentGeniricClassName;
	
	// constructor
	public BaseBo() {
		Type t = getClass().getGenericSuperclass();
		ParameterizedType pt = (ParameterizedType) t;
		type = (Class<E>) pt.getActualTypeArguments()[0];
		currentGeniricClassName = getClassNameFromPackage();
	}
	
	@Override
	public void save(E e) {
		super.save(e);
	}
	
	@Override
	public void update(E e){
		super.update(e);
	}
	
	@Override
	public void delete(int id){
		super.delete(id);
	}
	
	@Override
	public  E findByID(int id){
		return super.findByID(id);
	}
	
	private String getClassNameFromPackage() {
		StringTokenizer strTkn = new StringTokenizer(type.toString(), ".");
		String temp = "";
		while (strTkn.hasMoreElements()) {
			temp = (String) strTkn.nextElement();
		}
		return temp;
	}

	public List<E> findAll(){
		return super.findAll();
		
	}
}
